
//
//  SettingView.m
//  mendianjieke
//
//  Created by 响当当 on 8/7/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//

#import "SettingView.h"
#import "LoginViewController.h"

@interface SettingView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)UIView *footView;
@end

@implementation SettingView

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = 0;
        _tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.tableFooterView = self.footView;
    }
    return _tableView;
}

- (UIView *)footView
{
    if (!_footView)
    {
        _footView = [[UIView alloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,50*kUIScaleBasePlus)];
        _footView.backgroundColor = [UIColor whiteColor];
        
        UIButton *logOutBtn = [Utilties creatButtonWithFrame:CGRectMake(0,0,SCREEN_WIDTH,50*kUIScaleBasePlus)
                                                textAligment:UIControlContentHorizontalAlignmentCenter
                                                        text:@"退出当前帐号"
                                                    textClor:LCHexColor(0x989898)
                                                   buttonBGC:[UIColor clearColor]
                                                    textFont:17*kUIScaleBasePlus
                                                      target:self
                                                      method:@selector(logOut)];
        [_footView addSubview:logOutBtn];
        
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,1*kUIScaleBasePlus)];
        lineView.backgroundColor = JSALineColor;
        [_footView addSubview:lineView];
    }
    
    return _footView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self addSubview:self.tableView];
    }
    return self;
}


#pragma mark - delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return SCREEN_HEIGHT - 50*kUIScaleBasePlus -NAVIBAR_HEIGHT;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [UITableViewCell new];
}


- (void)logOut
{
    
    WeakSelf(self)
    [infoManager logOut:[NSDictionary new]
                 sucess:^(id  _Nonnull acceptData) {
                     LoginViewController *vc = [[LoginViewController alloc]init];
                     vc.hidesBottomBarWhenPushed = YES;
                     [[Utilties getCurrentVC].navigationController presentViewController:vc animated:YES completion:nil];
                 }
                   fail:^(NSError * _Nullable error) {
                       
                   }];
}
@end
